From: Colin Walters Date: Sun, 24 Jul 2016 19:40:49 +0000 (-0400) Subject: deploy: Fix leaks in parsing /etc/os-release X-Git-Tag: archive/raspbian/2022.1-3+rpi1~1^2~4^2~49^2~54 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:///%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:/?a=commitdiff_plain;h=27559c58a980dabebabd93d7c522537b664e161d;p=ostree.git deploy: Fix leaks in parsing /etc/os-release This one is a bit subtle; we're generating a hash that contains pointers to the strings we parsed, so we need to carefully track ownership. Closes: #410 Approved by: giuseppe --- diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index cc1a1faa..246a3412 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -1244,13 +1244,13 @@ static GHashTable * parse_os_release (const char *contents, const char *split) { - char **lines = g_strsplit (contents, split, -1); + g_autofree char **lines = g_strsplit (contents, split, -1); char **iter; GHashTable *ret = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); for (iter = lines; *iter; iter++) { - char *line = *iter; + g_autofree char *line = *iter; char *eq; const char *quotedval; char *val; @@ -1268,7 +1268,7 @@ parse_os_release (const char *contents, if (!val) continue; - g_hash_table_insert (ret, line, val); + g_hash_table_insert (ret, g_steal_pointer (&line), val); } return ret;